Japanese Patent Laid-Open No. 2003-209639 describes a header inserting method (JPEG (Joint Photographic Experts Group) encoded data conversion method) with re-encoding processing. That method inserts a header into JPEG encoded data by deleting 0x00, which follows 0xFF, from the JPEG encoded data, bit-shifting attached JPEG encoded data by header insertion, and inserting 0x00 after 0xFF into the bit-shifted JPEG encoded data.
A data structure of a JPEG encoded image will be briefly described with reference to FIG. 10.
A JPEG image is generated by encoding an inputted original image is divided into blocks of 8 pixels×8 pixels. First, DCT (Discrete Cosine Transform) processing and quantization processing are performed for each block of 8 pixels×8 pixels. A block denoted by the reference numeral 1001 in FIG. 10 represents a block after the DCT processing. Each pixel after the DCT processing is called a DCT coefficient. Huffman encoding is performed after the DCT processing. The Huffman encoding is performed in the order of the numbers given to each pixel in the block 1001 of FIG. 10.
In the block 1001, 0th coefficient is called a DC coefficient and the other coefficients are called AC coefficients.
The reference numeral 1002 of FIG. 10 denotes an MCU (Minimum Coded Unit). The MCU is a set of blocks 1001. In the example of FIG. 10, four blocks make one MCU.
A set of MCUs makes a JPEG encoded image. Between an MCU and an MCU, a marker code called an RST marker (Restart Marker) can be inserted at a certain interval. The RST markers may or may not be inserted. The RST markers may be inserted at any interval. FIG. 10 shows a case where an RST marker 1003 is inserted for every two MCUs. The marker code of JPEG must be inserted as it is byte-aligned. Therefore, when an RST marker 1003 is inserted, “1” bit needs to be inserted by the number necessary to byte-align and the RST marker needs to be inserted after the byte-align.
When the DC coefficient in a block is encoded, a DC coefficient of a previously encoded block is used. That is called DC coefficient prediction. The DC coefficient prediction is effective in an interval for an RST marker to be inserted. The DC coefficient prediction is not performed on a block immediately after an RST marker is inserted.
A JPEG image is subjected to processing called byte stuff processing. The byte stuff processing is the processing for inserting 0x00 immediately after 0xFF code when 0xFF code in a byte-aligned state is in a JPEG image. In order to decode the processed image, the inserted 0x00 is deleted first, and then decoding processing is performed.
A usual procedure for inserting an RST marker into a JPEG encoding image without an RST marker being inserted will be described with reference to FIG. 11.
FIG. 11 is a flowchart showing a conversion procedure for inserting an RST marker into a JPEG encoded image without an RST marker being inserted and converting it into a JPEG encoded image with an RST marker being inserted.
First at step S1101, changing processing is performed on a header. At this step, a marker code indicating that the JPEC encoded image includes an RST marker is added. The other headers are not changed.
Conversion processing is performed by each MCU. At step S1102, decoding processing is performed on an MCU. The decoding processing is the Huffman decoding processing and the DC coefficient prediction decoding processing. In this conversion processing, neither invert quantization processing nor invert DCT processing is needed. Decoding processing up to the DC coefficient prediction is performed here from the viewpoint of conversion efficiency. The DCT coefficient prediction is needed because a DC coefficient prediction is reset after an RST marker is inserted and a DC coefficient value of an MCU immediately after the RST marker is inserted changes.
After decoding processing of an MCU, encoding processing is performed on an MCU as shown in step S1103. The encoding processing performed in this step is a re-encoding of a DC coefficient value and a byte stuff processing. The re-encoding of a DC coefficient value is performed when DC coefficient prediction processing changes due to RST marker insertion as mentioned above. Similarly, the byte stuff processing has to be performed again because an encoded image is bit-shifted when an RST marker is inserted. Japanese Patent Laid-Open No. 2003-209639 describes a method for performing byte stuff processing again and re-converting a JPEG encoded image. At step S1104, whether or not to insert an RST marker is determined. Insertion of an RST marker is performed for each previously designated MCU interval. After the designated MCU decoding processing and encoding processing, insertion of an RST marker is performed at step S1105. As mentioned above, when an RST marker is inserted, byte-align processing is performed and the head position of an RST marker is set to the head position of a byte.
Processing mentioned above is performed on all the MCUs in a JPEG image. Then, the conversion processing of the JPEG image ends.
As mentioned above, in usual conversion processing performed when an RST marker is inserted into a JPEG image encoded image, decoding processing and encoding processing (re-encoding processing of a DC coefficient and byte stuff processing) have to be performed on all the MCUs. That causes a problem of slowing the conversion processing.
The encoded data conversion method of the present invention adds codes for avoiding bit-shift after predetermined data is inserted to eliminate byte stuff processing which is applied to an encoded image. As the invention described in Japanese Patent Laid-Open No. 2003-209639 does not have this technique, it needs a series of re-encoding processing including deletion of 0x00 which follows 0xFF in unconverted JPEG encoded data, bit-shift processing due to insertion of predetermined data, and insertion of 0x00 after 0xFF into bit-shifted JPEG encoded data, as described in the claim 4 in Japanese Patent Laid-Open No. 2003-209639.
The invention described in Japanese Patent Laid-Open No. 2003-209639 has a problem in that it slows down conversion processing as when it performs conversion by inserting a header into JPEG encoded data it needs re-encoding processing of JPEG encoded data.